<?php

/**
 * sfGuardUser filter form base class.
 *
 * @package    sfwixet
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BasesfGuardUserFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'username'                                => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'firstName'                               => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'lastName'                                => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'secondLastName'                          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'email_address'                           => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'algorithm'                               => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'salt'                                    => new sfWidgetFormFilterInput(),
      'password'                                => new sfWidgetFormFilterInput(),
      'language_id'                             => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('language'), 'add_empty' => true)),
      'theme_id'                                => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('theme'), 'add_empty' => true)),
      'is_active'                               => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'is_super_admin'                          => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'last_login'                              => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'main_album_id'                           => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('mainAlbum'), 'add_empty' => true)),
      'main_photo_id'                           => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('face'), 'add_empty' => true)),
      'main_group_id'                           => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('mainGroup'), 'add_empty' => true)),
      'main_private_messages_directory_id'      => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('mainPrivateMessagesDirectory'), 'add_empty' => true)),
      'main_private_messages_sent_directory_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('mainPrivateMessagesSentDirectory'), 'add_empty' => true)),
      'last_activity'                           => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'font_id'                                 => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('font'), 'add_empty' => true)),
      'text_color'                              => new sfWidgetFormFilterInput(),
      'created_at'                              => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'                              => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'groups_list'                             => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardGroup')),
      'acl_groups_list'                         => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'aclGroup')),
      'permissions_list'                        => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardPermission')),
    ));

    $this->setValidators(array(
      'username'                                => new sfValidatorPass(array('required' => false)),
      'firstName'                               => new sfValidatorPass(array('required' => false)),
      'lastName'                                => new sfValidatorPass(array('required' => false)),
      'secondLastName'                          => new sfValidatorPass(array('required' => false)),
      'email_address'                           => new sfValidatorPass(array('required' => false)),
      'algorithm'                               => new sfValidatorPass(array('required' => false)),
      'salt'                                    => new sfValidatorPass(array('required' => false)),
      'password'                                => new sfValidatorPass(array('required' => false)),
      'language_id'                             => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('language'), 'column' => 'language_id')),
      'theme_id'                                => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('theme'), 'column' => 'theme_id')),
      'is_active'                               => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'is_super_admin'                          => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'last_login'                              => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'main_album_id'                           => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('mainAlbum'), 'column' => 'album_id')),
      'main_photo_id'                           => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('face'), 'column' => 'photo_id')),
      'main_group_id'                           => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('mainGroup'), 'column' => 'group_id')),
      'main_private_messages_directory_id'      => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('mainPrivateMessagesDirectory'), 'column' => 'id')),
      'main_private_messages_sent_directory_id' => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('mainPrivateMessagesSentDirectory'), 'column' => 'id')),
      'last_activity'                           => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'font_id'                                 => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('font'), 'column' => 'font_id')),
      'text_color'                              => new sfValidatorPass(array('required' => false)),
      'created_at'                              => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'                              => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'groups_list'                             => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardGroup', 'required' => false)),
      'acl_groups_list'                         => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'aclGroup', 'required' => false)),
      'permissions_list'                        => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardPermission', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('sf_guard_user_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addGroupsListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.sfGuardUserGroup sfGuardUserGroup')
      ->andWhereIn('sfGuardUserGroup.group_id', $values)
    ;
  }

  public function addAclGroupsListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.aclUsersGroups aclUsersGroups')
      ->andWhereIn('aclUsersGroups.group_id', $values)
    ;
  }

  public function addPermissionsListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.sfGuardUserPermission sfGuardUserPermission')
      ->andWhereIn('sfGuardUserPermission.permission_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'sfGuardUser';
  }

  public function getFields()
  {
    return array(
      'id'                                      => 'Number',
      'username'                                => 'Text',
      'firstName'                               => 'Text',
      'lastName'                                => 'Text',
      'secondLastName'                          => 'Text',
      'email_address'                           => 'Text',
      'algorithm'                               => 'Text',
      'salt'                                    => 'Text',
      'password'                                => 'Text',
      'language_id'                             => 'ForeignKey',
      'theme_id'                                => 'ForeignKey',
      'is_active'                               => 'Boolean',
      'is_super_admin'                          => 'Boolean',
      'last_login'                              => 'Date',
      'main_album_id'                           => 'ForeignKey',
      'main_photo_id'                           => 'ForeignKey',
      'main_group_id'                           => 'ForeignKey',
      'main_private_messages_directory_id'      => 'ForeignKey',
      'main_private_messages_sent_directory_id' => 'ForeignKey',
      'last_activity'                           => 'Date',
      'font_id'                                 => 'ForeignKey',
      'text_color'                              => 'Text',
      'created_at'                              => 'Date',
      'updated_at'                              => 'Date',
      'groups_list'                             => 'ManyKey',
      'acl_groups_list'                         => 'ManyKey',
      'permissions_list'                        => 'ManyKey',
    );
  }
}
